//
//  UIColor+TYZAdd.m
//  DrivieSchoolStudents
//
//  Created by TangBin on 2019/6/5.
//  Copyright © 2019 班文政. All rights reserved.
//

#import "UIColor+TYZAdd.h"

@implementation UIColor (TYZAdd)

/**
 随机颜色
 
 @return 返回随机的颜色
 */
+ (UIColor *)colorWithRandom
{
    return [UIColor colorWithRed: ((float)arc4random_uniform(256) / 255.0) green:((float)arc4random_uniform(256) / 255.0) blue:((float)arc4random_uniform(256) / 255.0) alpha:1.0];
}

+ (CAGradientLayer *)setGradualChangingColor:(CGRect)bounds fromColor:(UIColor *)fromColor toColor:(UIColor *)toColor isVertical:(BOOL)isVertical
{
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = bounds;
    
    gradientLayer.colors = @[(__bridge id)fromColor.CGColor, (__bridge id)toColor.CGColor];
    
    // startPoint & endPoint设置为(0,0)(1.0,0)代表水平方向渐变,(0,0)(0,1.0)代表竖直方向渐变
    if (isVertical)
    {
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(0, 1.0);
    }
    else
    {
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1.0, 0);
    }
    
    // 设置颜色变化点，气质范围0~1
    gradientLayer.locations = @[@0, @1];
    return gradientLayer;
}


@end
